﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbAlternativeTitlesTest and is intended
    ///     to contain all TmdbAlternativeTitlesTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbAlternativeTitlesTest
    {
        /// <summary>
        ///     A test for TmdbAlternativeTitles Constructor
        /// </summary>
        [TestMethod]
        public void TmdbAlternativeTitlesConstructorTest()
        {
            var target = new TmdbAlternativeTitles();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbAlternativeTitles();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Id = expected;
            int actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Titles
        /// </summary>
        [TestMethod]
        public void TitlesTest()
        {
            var target = new TmdbAlternativeTitles();
            var expected = new List<TmdbAlternativeTitle>();
            target.Titles = expected;
            var actual = target.Titles;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\alternativeTitles.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbAlternativeTitles();
            var jsonContent = File.ReadAllText("alternativeTitles.json.txt");
            var actual = await target.DeserializeJson<TmdbAlternativeTitles>(jsonContent);

            Assert.AreEqual(550, actual.Id);
            Assert.AreEqual( 3, actual.Titles.Count );

            Assert.AreEqual( "PL", actual.Titles[ 0 ].Iso3166_1 );
            Assert.AreEqual("Podziemny krag", actual.Titles[0].Title);

            Assert.AreEqual("TW", actual.Titles[1].Iso3166_1);
            Assert.AreEqual("?????", actual.Titles[1].Title);

            Assert.AreEqual("HU", actual.Titles[2].Iso3166_1);
            Assert.AreEqual("Harcosok klubja", actual.Titles[2].Title);
        }
    }
}